<?php 
	
	class Acd_server_model extends CI_Model {
		
		 var $tblName = "ACD_servers";
		 
		function __construct()
		{
			parent::__construct();
		}
		
		function delete($id)
		{
			$id = (int)$id;
			$where = " ( primary_server_id  = {$id} OR secondary_server_id = {$id} ) ";
			if(! $this->common_model->record_exist("Skill_Mapping", $where))
			{
				$this->db->delete($this->tblName, array('id' => $id));
				DB_modification_logs("acd_servers");
				return TRUE;
			}
			else
			{
				return FALSE;	
			}
		}
				
		function save($record)
		{
			if( isset($record['id']) ) 
			{
				$this->db->where('id', $record['id']);
				unset($record['id']);				
				$this->db->update($this->tblName, $record);
			}
			else
			{
				$this->db->insert($this->tblName, $record);
			}
			
			DB_modification_logs("acd_servers");
		}
		
		function getDetailByID($id)
		{
		  $sql = "SELECT * FROM " . $this->tblName . " WHERE id= " . intval($id);
		  return $this->db->query($sql)->row_array();
		}
		
		function getAllRecords()
		{
		  $sql = "SELECT * FROM " . $this->tblName . " order by id ";
		  return $this->db->query($sql)->result();
		}
		
		function getListingData($GET)
		{
 			$where = '';
			if( isset($GET['server_ip']) && trim($GET['server_ip']) != '' )
			{
				$where  .= " WHERE server_ip LIKE '%".trim($this->db->escape($GET['server_ip']),"'")."%' ";	
			}
			$sql = "SELECT * FROM " . $this->tblName . " {$where} order by id";
			return $this->db->query($sql)->result();	
		}
  }
?>